package site.jlopen.entity;

public class BaseResponse<T> {

	private int status;
	
	private String msg;
	
	private T data;

	public BaseResponse() {
		super();
	}
	
	public BaseResponse<T> dbRes(int row, String successMsg, String errorMsg) {
		if(row > 0) {
			return success(successMsg);
		}
		return error(errorMsg);
	}
	
	public BaseResponse<T> dbRes(int row, String successMsg) {
		if(row > 0) {
			return success(successMsg);
		}
		return error("操作失败");
	}
	
	public BaseResponse<T> success(String msg) {
		BaseResponse<T> resp= new BaseResponse<T>(0, msg);
		return resp;
	}
	
	public BaseResponse<T> success(String msg, T data) {
		BaseResponse<T> resp= new BaseResponse<T>(0, msg, data);
		return resp;
	}
	
	public BaseResponse<T> error(String msg) {
		BaseResponse<T> resp= new BaseResponse<T>(1, msg);
		return resp;
	}

	public BaseResponse(int status, String msg, T data) {
		super();
		this.status = status;
		this.msg = msg;
		this.data = data;
	}

	public BaseResponse(int status, String msg) {
		super();
		this.status = status;
		this.msg = msg;
	}

	public int getStatus() {
		return status;
	}

	public BaseResponse<T> setStatus(int status) {
		this.status = status;
		return this;
	}

	public String getMsg() {
		return msg;
	}

	public BaseResponse<T> setMsg(String msg) {
		this.msg = msg;
		return this;
	}

	public T getData() {
		return data;
	}

	public BaseResponse<T> setData(T data) {
		this.data = data;
		return this;
	}
	
}
